extends StateBase

##飞船节点
@export var ship: BaseShip

func enter() -> void:
	super.enter()
	ship.animation_player.play("hurt")
	
	if ship.stats.energy_shield >= ship.pending_damage.amount:
		ship.stats.energy_shield -= ship.pending_damage.amount
	else:
		ship.pending_damage.amount -= ship.stats.energy_shield
		ship.stats.energy_shield = 0
		ship.stats.structural_strength -= ship.pending_damage.amount
	
	if ship.stats.structural_strength == 0:
		state_machine.change_state("Dying")
	
	ship.pending_damage = null
	ship.invincible_timer.start()

func physics_process_update(delta: float) -> void:
	super.physics_process_update(delta)
	if not ship.animation_player.is_playing():
		state_machine.change_state("Running")
	
	ship.move(ship.stats.running_speed)
